<template>
	<view>
		<qiun-title-bar title="博客类型比例"></qiun-title-bar>
		<view class="charts-box">
			<qiun-data-charts type="pie" :opts="{legend:{float:'left',fontSize:15}}" :chartData="pie" />
		</view>
		<qiun-title-bar title="最新博客分析"></qiun-title-bar>
		<view class="charts-box">
			<qiun-data-charts type="column" canvasId="scrollcolumnid"
				:opts="{enableScroll:true,xAxis:{scrollShow:true,itemCount:4,disableGrid:true,fontSize:15}}"
				:ontouch="true" :canvas2d="true" :chartData="column" />
		</view>
		<qiun-title-bar title="常用标签词云"></qiun-title-bar>
		<view class="charts-box">
			<qiun-data-charts type="word" :chartData="word" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pie: {},
				column: {},
				word: {},
			}
		},
		onLoad() {
			this.getCategories()
			this.getTopBlogs()
			this.getTags()
		},
		methods: {
			getCategories() {
				this.pie = {
					"series": [{
						"data": []
					}],
				}
				let url = this.$par.host + this.$par.action_categories
				this.$req.get(url, res => {
					url = this.$par.host + this.$par.action_category_count
					res.data.data.forEach(async (c) => {
						// 发送请求
						let r = await this.$req.requestAsync(url + c.id)
						if (r.success && r.data > 0) {
							let item = {
								name: c.name,
								value: r.data
							}
							this.pie.series[0].data.push(item)
						}
					})
				})
			},
			getTopBlogs() {
				this.column = {
					categories: [],
					series: [{
							name: "阅读量",
							data: []
						},
						{
							name: "评论数",
							data: []
						}
					]
				}
				let url = this.$par.host + this.$par.action_top_blogs
				this.$req.get(url, res => {
					console.log(res.data.data);
					res.data.data.forEach(b => {
						if (b.title.length > 10) {
							b.title = b.title.substr(0, 8) + "..."
						}
						this.column.categories.push(b.title)
						this.column.series[0].data.push(b.readCount)
						this.column.series[1].data.push(b.comments.length)

					})
				})
			},
			getTags() {
				this.word = {
					series: []
				}
				let url = this.$par.host + this.$par.action_tags
				this.$req.get(url, res => {
					url = this.$par.host + this.$par.action_tags_count
					res.data.data.forEach(async (c) => {
						// 发送请求
						let r = await this.$req.requestAsync(url + c.id)
						if (r.success && r.data > 0) {
							let item = {
								name: c.name,
								textSize: parseInt(r.data) * 10
							}
							this.word.series.push(item)
						}
					})
				})
			},
		}
		}
</script>

<style>

</style>